-- io.read()
-- "a" --> read the whole file (all)
-- "l" --> read a line without \n
-- "L" --> read a line with \n
-- "n" --> read a number
-- num --> read num characters as a string

-- io.write()

---[[ example 1
for count = 1, math.huge do
	local line = io.read("L")
	if line == nil then break end
	io.write(string.format("%6d  ", count), line) 	-- write will auto concat
end
--]]

--[[ example 2	 
local count = 0
for line in io.lines() do
	count = count + 1
	io.write(string.format("%6d  ", count), line)
end
--]]

--[[ example 3
local lines = {}
-- put the read line into table 'lines'
for line in io.lines() do
	lines[#lines + 1] = line
end
-- sort
table.sort(lines)
-- output all lines
for _, l in ipairs(lines) do
	io.write(l, "\n")
end
--]]

--[[ example 4
-- copy the data from stdio to stdout
while true do
	local block = io.read(2^13) 	-- block size is 8kb here
	if not block then break end
	io.write(block)
end
--]]

--[[ example 5
io.read(0) 	-- used to test is a file is end
						-- yes --> return nil
						-- no  --> return "" (empty string)
--]]

--[[ example 6
-- read more than one numbers once
while true do
	local n1, n2, n3 = io.read("n", "n", "n")
	if not n1 then break end
	print(math.max(n1, n2, n3))
end
--]]
